<?php
namespace console\controllers;

use Yii;
use yii\console\Controller;

class RbacController extends Controller
{
    public function actionInit()
    {
        $auth = Yii::$app->authManager;

        // 添加 "新建管理员" 权限
        $createAdmin = $auth->createPermission('createAdmin');
        $createAdmin->description = '新建管理员';
        $auth->add($createAdmin);

        // 添加 "管理管理员" 权限
        $updateAdmin = $auth->createPermission('updateAdmin');
        $updateAdmin->description = '管理管理员';
        $auth->add($updateAdmin);

        // 添加 "分配角色" 权限
        $assignRole = $auth->createPermission('assignRole');
        $assignRole->description = '分配角色';
        $auth->add($assignRole);

        // 添加 "新建员工" 权限
        $createEmployee = $auth->createPermission('createEmployee');
        $createEmployee->description = '新建员工';
        $auth->add($createEmployee);

        // 添加 "管理员工" 权限
        $updateEmployee = $auth->createPermission('updateEmployee');
        $updateEmployee->description = '管理员工';
        $auth->add($updateEmployee);

        // 添加 "新建部门" 权限
        $createDepartment = $auth->createPermission('createDepartment');
        $createDepartment->description = '新建部门';
        $auth->add($createDepartment);

        // 添加 "管理部门" 权限
        $updateDepartment = $auth->createPermission('updateDepartment');
        $updateDepartment->description = '管理部门';
        $auth->add($updateDepartment);

        // 添加 "新建流程" 权限
        $createProcess = $auth->createPermission('createProcess');
        $createProcess->description = '新建流程';
        $auth->add($createProcess);

        // 添加 "管理流程" 权限
        $updateProcess = $auth->createPermission('updateProcess');
        $updateProcess->description = '管理流程';
        $auth->add($updateProcess);

        // 添加 "新建产品" 权限
        $createProduct = $auth->createPermission('createProduct');
        $createProduct->description = '新建产品';
        $auth->add($createProduct);

        // 添加 "管理产品" 权限
        $updateProduct = $auth->createPermission('updateProduct');
        $updateProduct->description = '管理产品';
        $auth->add($updateProduct);

        // 添加 "统计查询" 权限
        $checkStatistic = $auth->createPermission('checkStatistic');
        $checkStatistic->description = '统计查询';
        $auth->add($checkStatistic);

        // 添加 "日志查询" 权限
        $checkLog = $auth->createPermission('checkLog');
        $checkLog->description = '日志查询';
        $auth->add($checkLog);

        // 添加 "执行任务" 权限
        $prepareTask = $auth->createPermission('prepareTask');
        $prepareTask->description = '执行任务';
        $auth->add($prepareTask);

        // 添加 "查看已执行任务" 权限
        $doneTask = $auth->createPermission('doneTask');
        $doneTask->description = '查看已执行任务';
        $auth->add($doneTask);

        // 添加 "超级管理员" 角色并赋予权限
        $super_admin = $auth->createRole('super_admin');
        $super_admin->description = "超级管理员";
        $super_admin->data = "1";
        $auth->add($super_admin);
        $auth->addChild($super_admin, $createAdmin);
        $auth->addChild($super_admin, $updateAdmin);
        $auth->addChild($super_admin, $assignRole);
        $auth->addChild($super_admin, $createEmployee);
        $auth->addChild($super_admin, $updateEmployee);
        $auth->addChild($super_admin, $createDepartment);
        $auth->addChild($super_admin, $updateDepartment);
        $auth->addChild($super_admin, $createProcess);
        $auth->addChild($super_admin, $updateProcess);
        $auth->addChild($super_admin, $createProduct);
        $auth->addChild($super_admin, $updateProduct);
        $auth->addChild($super_admin, $checkStatistic);
        $auth->addChild($super_admin, $checkLog);
        $auth->addChild($super_admin, $prepareTask);
        $auth->addChild($super_admin, $doneTask);

        $auth->assign($super_admin, 1);
    }
}



































